package jdom;
import java.util.ArrayList;

import org.jdom.Element;

public class Library {

	private String id;
	private String name;
	private String version;
	private String language;
	private String source;

	private ArrayList<String> developers;

	private ArrayList<String> dependencies;

	/**
	 * @param id
	 */
	public Library(String id) {
		super();
		this.id = id;
	}

	/**
	 * @param id
	 * @param name
	 * @param version
	 * @param language
	 * @param source
	 * @param developers
	 * @param dependencies
	 */
	public Library(String id, String name, String version, String language,
			String source, ArrayList<String> developers,
			ArrayList<String> dependencies) {
		super();
		this.id = id;
		this.name = name;
		this.version = version;
		this.language = language;
		this.source = source;
		this.developers = developers;
		this.dependencies = dependencies;
	}

	/**
	 * @param lib
	 */
	public Element convertToXmlElement() {
		Element result = new Element(XmlTags.TAG_LIBRARY);

		result.setAttribute(XmlTags.TAG_LIBRARY_ATTRIBUTE_LIBRARY_ID,
				this.getId());

		Element element;

		element = new Element(XmlTags.TAG_LIBRARY_TAG_NAME);
		element.setText(this.getName());
		result.addContent(element);
		element = new Element(XmlTags.TAG_LIBRARY_TAG_VERSION);
		element.setText(this.getVersion());
		result.addContent(element);
		element = new Element(XmlTags.TAG_LIBRARY_TAG_LANGUAGE);
		element.setText(this.getLanguage());
		result.addContent(element);
		element = new Element(XmlTags.TAG_LIBRARY_TAG_SOURCE);
		element.setText(this.getSource());
		result.addContent(element);

		for (String dev : this.getDevelopers()) {
			element = new Element(XmlTags.TAG_LIBRARY_TAG_DEVELOPER);
			element.setAttribute(
					XmlTags.TAG_LIBRARY_TAG_DEVELOPER_ATTRIBUTE_REF, dev);
			result.addContent(element);
		}
		for (String dep : this.getDependencies()) {
			element = new Element(XmlTags.TAG_LIBRARY_TAG_DEPENDENCY);
			element.setAttribute(
					XmlTags.TAG_LIBRARY_TAG_DEPENDENCY_ATTRIBUTE_REF, dep);
			result.addContent(element);
		}

		return result;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(String id) {
		if (id != null) {
			this.id = id;
		} else {
			this.id = "";
		}
	}

	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		if (name != null) {
			this.name = name;
		} else {
			this.name = "";
		}
	}

	/**
	 * @return the version
	 */
	public String getVersion() {
		return version;
	}

	/**
	 * @param version
	 *            the version to set
	 */
	public void setVersion(String version) {
		if (version != null) {
			this.version = version;
		} else {
			this.version = "";
		}
	}

	/**
	 * @return the language
	 */
	public String getLanguage() {
		return language;
	}

	/**
	 * @param language
	 *            the language to set
	 */
	public void setLanguage(String language) {
		if (language != null) {
			this.language = language;
		} else {
			this.language = "";
		}
	}

	/**
	 * @return the source
	 */
	public String getSource() {
		return source;
	}

	/**
	 * @param source
	 *            the source to set
	 */
	public void setSource(String source) {
		if (source != null) {
			this.source = source;
		} else {
			this.source = "";
		}
	}

	/**
	 * @return the developers
	 */
	public ArrayList<String> getDevelopers() {
		return developers;
	}

	/**
	 * @param developers
	 *            the developers to set
	 */
	public void setDevelopers(ArrayList<String> developers) {
		this.developers = developers;
	}

	/**
	 * @return the dependencies
	 */
	public ArrayList<String> getDependencies() {
		return dependencies;
	}

	/**
	 * @param dependencies
	 *            the dependencies to set
	 */
	public void setDependencies(ArrayList<String> dependencies) {
		this.dependencies = dependencies;
	}

}
